package com.jiayang.hhotel.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jiayang.hhotel.R;
import com.jiayang.hhotel.app.App;
import com.jiayang.hhotel.bean.LoginModel;

import java.util.List;

/**
 * Created by Administrator on 2017/5/24 0024.
 * 首页菜单列表适配器
 */
public class HomeMenuAdapter extends BaseAdapter{

    private Context t;
    private List<LoginModel.LoginBean.PRightIdDtolistBean> mList;
    private OnItemClickListener listener;

    public HomeMenuAdapter(Context context, List<LoginModel.LoginBean.PRightIdDtolistBean> list,OnItemClickListener listener){
        this.t = context;
        this.mList = list;
        this.listener = listener;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        final LoginModel.LoginBean.PRightIdDtolistBean model=mList.get(position);
        ViewHolder holder;
        if(convertView == null){
            convertView = LayoutInflater.from(t).inflate(R.layout.home_gridview_menu_item,null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        holder = (ViewHolder) convertView.getTag();
        holder.title.setText(model.getChnDescp());
        if(App.most_issueMap.containsKey(model.getCode())){
            holder.click.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if(listener != null){
                        listener.OnItemClick(model.getCode());
                    }
                }
            });
            holder.icon.setImageResource(App.most_issueMap.get(model.getCode()));
        }
        return convertView;
    }

    public class ViewHolder{

        LinearLayout click;//点击布局
        TextView title;//菜单文字
        ImageView icon;//图片

        public ViewHolder(View view){
            click = (LinearLayout) view.findViewById(R.id.ll_menu_click);
            title = (TextView) view.findViewById(R.id.tv_title);
            icon = (ImageView) view.findViewById(R.id.iv_icon);
        }
    }

    public interface OnItemClickListener {
        void OnItemClick(String id);//标记当前点击的权限代码
    }
}
